

import 'package:flutter/cupertino.dart';
import 'package:sjx/repository/sjx_api.dart';

import '../../../../repository/model/task_detail_model.dart';
import '../../../../repository/model/task_process_step_model.dart';
import '../../../../repository/model/task_publish_process_model.dart';

class PublishTaskProcessViewModel with ChangeNotifier {
  TaskPublishProcessModel? _publishProcessModel;
  TaskDetailModel? _taskDetailModel;

  TaskPublishProcessModel? get publishProcessModel => _publishProcessModel;
  TaskDetailModel? get taskDetailModel => _taskDetailModel;

  bool get isLoading => _publishProcessModel == null || _taskDetailModel == null;

  // 请求任务订单详情
  Future<void> requestOrderDetail(String taskNo) async {
    try {
      _taskDetailModel = await SJXApi.instance().taskDetail(taskNo);
      notifyListeners();
    } catch (e) {
      print('请求任务详情失败: $e');
    }
  }

  // 请求任务进程
  Future<void> requestOrderProcess(String taskNo) async {
    try {
      _publishProcessModel = await SJXApi.instance().taskPublishProcess(taskNo);
      notifyListeners();
    } catch (e) {
      print('请求任务进程失败: $e');
    }
  }

  // 刷新数据
  Future<void> refreshData(String taskNo) async {
    await requestOrderDetail(taskNo);
    await requestOrderProcess(taskNo);
  }
}